package cn.com.ejiakanghu.web;

import cn.com.ejiakanghu.annotation.LoginUser;
import cn.com.ejiakanghu.core.vo.BaseResult;
import cn.com.ejiakanghu.form.NearbySaleUserForm;
import cn.com.ejiakanghu.service.AgentManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 代理服务
 */
@RestController
@RequestMapping("/agent")
@Validated
public class AgentController {
    private Logger logger = LoggerFactory.getLogger(AgentController.class);
    @Autowired
    private AgentManager agentManager;

    /**
     * @api {post} /agent/addCombo 当前用户代理医生生成自定义组合商品
     * @apiGroup 代理服务
     * @apiParam {String} goodsIds 添加自定义组合的商品ID，多个商品ID英文逗号分隔
     * @apiParam {String} shareName 自定义组合名称
     * @apiVersion 0.1.0
     * @apiDescription 当前用户代理医生生成自定义组合商品
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/addCombo")
    public BaseResult addCombo(@LoginUser Integer userId, @RequestParam String goodsIds, @RequestParam String shareName) {
        return agentManager.addCombo(userId, goodsIds, shareName);
    }

    /**
     * @api {post} /agent/updateComboName 当前用户代理医生修改自定义组合名称
     * @apiGroup 代理服务
     * @apiParam {Integer} id 自定义组合ID
     * @apiParam {String} name 新的自定义组合名称
     * @apiVersion 0.1.0
     * @apiDescription 当前用户代理医生修改自定义组合名称
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/updateComboName")
    public BaseResult updateComboName(@LoginUser Integer userId, @RequestParam Integer id, @RequestParam String name) {
        return agentManager.updateComboName(userId, id, name);
    }

    /**
     * @api {post} /agent/deleteBatch 批量删除当前用户代理医生的自定义组合
     * @apiGroup 代理服务
     * @apiParam {String} ids 自定义组合ID，多个英文逗号分隔
     * @apiVersion 0.1.0
     * @apiDescription 批量删除当前用户代理医生的自定义组合
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/deleteBatch")
    public BaseResult deleteBatch(@LoginUser Integer userId, @RequestParam String ids) {
        return agentManager.updateComboName(userId, ids);
    }

    /**
     * @api {post} /agent/comboList 获取当前用户代理医生的自定义组合商品列表
     * @apiGroup 代理服务
     * @apiParam {String} keyword 查询关键字
     * @apiParam {Integer} page 当前页
     * @apiParam {Integer} pageSize 页大小
     * @apiVersion 0.1.0
     * @apiDescription 获取当前用户代理医生的自定义组合商品列表
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/comboList")
    public BaseResult comboList(@LoginUser Integer userId,
                                  @RequestParam(required = false) String keyword,
                                  @RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pageSize) {
        return agentManager.comboList(userId, keyword, page, pageSize);
    }

    /**
     * @api {post} /agent/shareComboList 获取分享的自定义组合商品列表
     * @apiGroup 代理服务
     * @apiParam {String} ids 自定义组合ID，多个英文逗号分隔
     * @apiVersion 0.1.0
     * @apiDescription 获取分享的自定义组合商品列表
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/shareComboList")
    public BaseResult shareComboList(@RequestParam String ids) {
        return agentManager.shareComboList(ids);
    }

    /**
     * @api {post} /agent/goodsList 获取普通推广员的推广商品列表数据
     * @apiGroup 代理服务
     * @apiParam {String} keyword 查询关键字
     * @apiParam {Integer} page 当前页
     * @apiParam {Integer} pageSize 页大小
     * @apiVersion 0.1.0
     * @apiDescription 获取普通推广员的推广商品列表数据
     * @apiSuccess {Object} Object
     * @apiSuccessExample {json} Success-Response:
     * { "msg": "成功", "code":0, "data": {} }
     */
    @RequestMapping("/goodsList")
    public BaseResult goodsList(@RequestParam Integer saleUserId,
                                @RequestParam(required = false) String keyword,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "30") Integer pageSize) {
        return agentManager.goodsList(saleUserId, keyword, page, pageSize);
    }


    /**
     * 获取附近的门店普通推广员ID
     */
    @PostMapping("/getNearbySaleUserId")
    public BaseResult getNearbySaleUserId(NearbySaleUserForm nearbySaleUserForm){

        return agentManager.getNearbySaleUserId(nearbySaleUserForm);
    }


}
